package com.np.moneylover;

import java.util.List;


import com.np.dao.CheckLoginData;
import com.np.dao.CheckLoginDataListener;
import com.np.dto.taikhoan;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import Util.*;
public class MoneyLover extends Activity implements CheckLoginDataListener, OnClickListener{

	EditText txttdn=null;
	EditText txtmk=null;
	Button btnok=null;
	Button btndangky=null;
	private ProgressDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dangnhap);
        this.setTitle("ĐĂNG NHÂP");
        
        txttdn=(EditText)findViewById(R.id.txttendangnhap);
        txtmk=(EditText)findViewById(R.id.txtpass);
        btnok=(Button)findViewById(R.id.btndnagnhap);
        btndangky = (Button)findViewById(R.id.btndangky);
        btnok.setOnClickListener(this);
        btndangky.setOnClickListener(this);
    }


    protected void DangNhap() {
		// TODO Auto-generated method stub
		//Kiem tra, neu thanh cong thi 
    	dialog = ProgressDialog.show(this, "", "Kiểm tra đăng nhập ...");
        //chay localhost thi la 10.0.2.2
        String url = "http://10.0.2.2:8080/connect_android/checklogin.php?username="+txttdn.getText().toString().trim()+"&password="+txtmk.getText().toString().trim();
        CheckLoginData task = new CheckLoginData(this);
        task.execute(url);
	}


	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.money_lover, menu);
        return true;
    }


	@Override
	public void onCheckLoginComplete(List<taikhoan> data) {
		// TODO Auto-generated method stub
		 if(dialog != null)  dialog.dismiss();
		 // gan va
		 taikhoan temp=data.get(0);
		 Constants._login=temp;
		  
		Intent I= new Intent(this, Main.class);
		startActivity(I);
	}




	@Override
	public void onCheckLoginFailure(String msg) {
		// TODO Auto-generated method stub
		 if(dialog != null)  dialog.dismiss();
		 Toast.makeText(this, "That bai", Toast.LENGTH_LONG).show();
	}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id= v.getId();
		switch (id) {
		case R.id.btndnagnhap:
			
			DangNhap();
			break;
		case R.id.btndangky:
			Intent I= new  Intent(this, DangKy.class);
			startActivity(I);
		default:
			break;
		}
	}


	private void Dangky(taikhoan a) {
		// TODO Auto-generated method stub
		
		
	}
    
}
